<?php

namespace Blog\App\Action;

use Hx\App;
use Hx\Request;
use Hx\Response;

/**
 * 辅助数据Action
 * Class Meta
 * @package Blog\App\Action
 */
class Meta {

    /**
     * 订阅数据
     * @return bool|string
     */
    public function feed() {
        Response::setHeader('Content-Type', 'application/rss+xml;charset=UTF-8');
        $meta = array(
            'title' => '傅小黑.COM',
            'link' => Request::$baseUrl,
            'description' => '傅小黑.COM',
            'language' => 'zh-CN'
        );
        return \Blog\ORG\Feed::render($meta, App::Model('Blog->getFeed'));
    }

    /**
     * 网站地图
     * @return bool|string
     */
    public function map() {
        Response::setHeader('Content-Type', 'text/xml;charset=UTF-8');
        $links = array();
        #顶级链接
        $links[] = array('loc' => Request::$baseUrl, 'lastmod' => date(DATE_ISO8601), 'changefreq' => 'daily',
            'priority' => '1.0');
        $links[] = array('loc' => Request::$baseUrl . 'all/', 'lastmod' => date(DATE_ISO8601), 'changefreq' => 'daily',
            'priority' => '0.8');
        $links[] = array('loc' => Request::$baseUrl . 'message/', 'lastmod' => date(DATE_ISO8601), 'changefreq' => 'daily',
            'priority' => '0.8');
        #博客链接
        $blog = App::Model('Blog->getAll', array(false));
        foreach ($blog as $b) {
            $links[] = array('loc' => Request::$baseUrl . 'p/' . $b->nodeKey . '.html',
                'lastmod' => date(DATE_ISO8601, $b->createDate),
                'changefreq' => 'monthly',
                'priority' => '0.2'
            );
        }
        #添加分类链接
        $category = App::Model('Category->getAll');
        foreach ($category as $c) {
            $links[] = array('loc' => Request::$baseUrl . 'category/' . $c->keyString . '/',
                'lastmod' => date(DATE_ISO8601, $c->createDate),
                'changefreq' => 'weekly',
                'priority' => '0.3'
            );
        }
        return \Blog\ORG\SiteMap::render($links, Request::$baseUrl . 'public/css/sitemap.xsl');
    }
}